// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/visitor/api/VisitorAppointmentApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/visitor/model/QueryVisitorAppointmentListReq'
import AddClass from '@api/visitor/model/InsertVisitorAppointmentReq'
import BaseClass from '@api/visitor/model/VisitorAppointmentDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'content']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryMyVisitorAppointmentList', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },
  transList(arr) {
    arr.forEach((item) => {
      item.auditStatus = item.cancelStatus === 1 ? 9 : item.auditStatus
    })
    return arr
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增') {
    const DTO = CORE.grpcDTO(AddClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'insertVisitorAppointment', DTO)
    return CORE.grpcOK(TIP)
  },
}
